<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">

<ui:composition template="/common/template.xhtml">

	<ui:define name="headSection">

	</ui:define>

	<ui:define name="pageContent">

		<h:form>
			<h:panelGroup>
				<table class="mainTable" style="margin-bottom: 10px;">
					<tr>
						<td><h:outputLabel value="Наименование">
								<h:inputText value="#{aktualiziraneNaZastrahovatel.searchName}"
									maxlength="100" />
							</h:outputLabel></td>
						<td>
							<table class="buttonTable">
								<tr>
									<td><h:commandButton value="Търси" class="regButton"
											style="width:80px;height:40px;margin-top: 20px;"
											action="#{aktualiziraneNaZastrahovatel.searchIt()}" /> <h:commandButton
											value="Изчисти" class="regButton"
											style="width:80px;height:40px;"
											action="#{aktualiziraneNaZastrahovatel.resetSearch()}" /></td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</h:panelGroup>
		</h:form>

		<div id="scroolTable">
			<!-- scroll bar -->
			<h:form>

				<!-- за Калин - избрания ред ще има клас = "selectedRow", неизбраните = "notSelectedRow" -->
				<h:dataTable rows="#{configurationProperties.getPageSize()}"
					value="#{aktualiziraneNaZastrahovatel.spisukZastrahovateli}"
					first="0" var="curr"
					rowClasses="#{aktualiziraneNaZastrahovatel.rowStyleClasses}">

					<h:column>
						<f:facet name="header">Наименование</f:facet>
					#{curr.name}
				</h:column>

					<h:column>
						<f:facet name="header">Лице за контакт</f:facet>
					#{curr.contactPerson}
				</h:column>

					<h:column>
						<f:facet name="header">Населено място</f:facet>
					#{curr.addressCity}
				</h:column>

					<h:column>
						<f:facet name="header">Адрес</f:facet>
					#{curr.addressLine}
				</h:column>

					<h:column>
						<f:facet name="header">Електронна поща</f:facet>
					#{curr.mail}
				</h:column>

					<h:column>
						<f:facet name="header">Телефонен номер</f:facet>
					#{curr.phoneNumber}
				</h:column>

					<h:column>
						<f:facet name="header">Номер на банковата сметка</f:facet>
					#{curr.IBANNumber}
				</h:column>

					<h:column>
						<f:facet name="header">Банков код</f:facet>
					#{curr.SWIFTCode}
				</h:column>

					<h:column>
						<f:facet name="header">ЕИК</f:facet>
					#{curr.registrationNumber}
				</h:column>

					<h:column>
						<f:facet name="header">ДДС номер</f:facet>
					#{curr.VATNumber}
				</h:column>

					<h:column>
						<f:facet name="header">Промени</f:facet>
						<h:commandButton
							action="#{aktualiziraneNaZastrahovatel.selectRow(curr)}"
							value="Промени" 
							class="inTableButton"/>
					</h:column>

					<h:column
						rendered="#{aktualiziraneNaZastrahovatel.choosingAllowed}">
						<f:facet name="header">Избери</f:facet>
						<h:commandLink
							action="#{aktualiziraneNaZastrahovatel.chooseAutoservice(curr)}"
							value="Избери" />
					</h:column>

					<f:facet name="footer">

						<!-- предишна страница -->
						<h:commandLink
							disabled="#{aktualiziraneNaZastrahovatel.page - 1 lt 0}"
							action="#{aktualiziraneNaZastrahovatel.setPage(aktualiziraneNaZastrahovatel.page - 1)}"
							value="&lt;&lt;" />

						<h:outputText value=" " />

						<!-- други страници -->
						<ui:repeat value="#{aktualiziraneNaZastrahovatel.pagesList}"
							var="currPage">
							<h:commandLink
								disabled="#{aktualiziraneNaZastrahovatel.getPage() eq currPage.intValue() - 1}"
								action="#{aktualiziraneNaZastrahovatel.setPage(currPage.intValue() - 1)}"
								value="#{currPage}" />

							<h:outputText value=" " />
						</ui:repeat>

						<!-- следваща страница -->
						<h:commandLink
							disabled="#{aktualiziraneNaZastrahovatel.page + 1 ge aktualiziraneNaZastrahovatel.pagesCount}"
							action="#{aktualiziraneNaZastrahovatel.setPage(aktualiziraneNaZastrahovatel.page + 1)}"
							value="&gt;&gt;" />

					</f:facet>

				</h:dataTable>
			</h:form>
		</div>

		<h:form>
			<table class="mainTable">
				<tr>
					<td><h:outputLabel value="Код за достъп">
							<br />
							<h:inputText id="key" value="#{aktualiziraneNaZastrahovatel.ID}"
								readonly="true" />
						</h:outputLabel></td>
					<td><h:outputLabel value="Наименование*">
							<br />
							<h:inputText id="name"
								value="#{aktualiziraneNaZastrahovatel.name}" maxlength="100"
								required="true" requiredMessage="задължително поле!"
								readonly="#{!aktualiziraneNaZastrahovatel.rowSelected}" 
								validatorMessage="Въведеното наименование е прекалено късо или съдържа некоректни символи.">
								<f:validateRegex pattern="^[а-яА-Я\s\w]{3,100}$" />
							</h:inputText>
							<br/>
							<h:message for="name" class="errorMsg" />
						</h:outputLabel></td>
					<td><h:outputLabel value="Лице за контакт*">
							<br />
							<h:inputText id="contactPerson"
								value="#{aktualiziraneNaZastrahovatel.contactPerson}"
								maxlength="100" required="true"
								requiredMessage="задължително поле!"
								readonly="#{!aktualiziraneNaZastrahovatel.rowSelected}" 
								validatorMessage="Въведеното лице за контакт съдържа некоректни символи или е прекалено късо.">
								<f:validateRegex pattern="^[a-zA-Zа-яА-Я\s]{2,100}$" />
							</h:inputText>
							<br/>
							<h:message for="contactPerson" class="errorMsg" />
						</h:outputLabel></td>
				</tr>
				<tr>
					<td><h:outputLabel value="Населено място*">
							<br />
							<h:inputText id="city"
								value="#{aktualiziraneNaZastrahovatel.addressCity}"
								maxlength="30" required="true"
								requiredMessage="задължително поле!"
								readonly="#{!aktualiziraneNaZastrahovatel.rowSelected}" 
								validatorMessage="Въведеното населено място съдържа некоректни символи или е прекалено късо.">
								<f:validateRegex pattern="^[a-zA-Zа-яА-Я]{3,30}$" />
							</h:inputText>
							<br/>
							<h:message for="city" class="errorMsg" />
						</h:outputLabel></td>
					<td><h:outputLabel value="Адрес*">
							<br />
							<h:inputText id="address"
								value="#{aktualiziraneNaZastrahovatel.addressLine}"
								maxlength="100" required="true"
								requiredMessage="задължително поле!"
								readonly="#{!aktualiziraneNaZastrahovatel.rowSelected}" 
								validatorMessage="Въведеният адрес е прекалено къс.">
								<f:validateRegex pattern="^.{5,100}$" />
							</h:inputText>
							<br/>
							<h:message for="address" class="errorMsg" />
						</h:outputLabel></td>
					<td><h:outputLabel value="Електронна поща*">
							<br />
							<h:inputText id="mail"
								value="#{aktualiziraneNaZastrahovatel.mail}" maxlength="50"
								required="true" requiredMessage="задължително поле!"
								readonly="#{!aktualiziraneNaZastrahovatel.rowSelected}"
								validatorMessage="Електронната поща е невалидна. Пример: potrbitel@mail.bg">
								<f:validateRegex pattern="^[a-zA-Z][a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4}$" />
							</h:inputText>
							<br/>
							<h:message for="mail" class="errorMsg" />
						</h:outputLabel></td>
				</tr>
				<tr>
					<td><h:outputLabel value="Телефонен номер*">
							<br />
							<h:inputText id="phone"
								value="#{aktualiziraneNaZastrahovatel.phoneNumber}"
								maxlength="15" required="true"
								requiredMessage="задължително поле!"
								readonly="#{!aktualiziraneNaZastrahovatel.rowSelected}"
								validatorMessage="Телефонният номер е невалиден. Примери: +359885609456, 082860450">
								<f:validateRegex pattern="^[+]?[0-9]{6,14}$" />
							</h:inputText>
							<br/>
							<h:message for="phone" class="errorMsg" />
						</h:outputLabel></td>
					<td><h:outputLabel value="Номер на банковата сметка*">
							<br />
							<h:inputText id="IBANNumber"
								value="#{aktualiziraneNaZastrahovatel.IBANNumber}"
								maxlength="30" required="true"
								requiredMessage="задължително поле!"
								readonly="#{!aktualiziraneNaZastrahovatel.rowSelected}"
								validatorMessage="Позволени символи за номер на сметка са главни латински букви и цифри. От 10 до 30 символа">
								<f:validateRegex pattern="^[A-Z0-9]{10,30}$" />
							</h:inputText>
							<br/>
							<h:message for="IBANNumber" class="errorMsg" />
						</h:outputLabel></td>
					<td><h:outputLabel value="Банков код*">
							<br />
							<h:inputText id="SWIFT"
								value="#{aktualiziraneNaZastrahovatel.SWIFTCode}" maxlength="11"
								required="true" requiredMessage="задължително поле!"
								readonly="#{!aktualiziraneNaZastrahovatel.rowSelected}"
								validatorMessage="Позволени символи за банков код са главни латински букви и цифри. От 8 до 11 символа.">
								<f:validateRegex pattern="^[A-Z0-9]{8,11}$" />
							</h:inputText>
							<br/>
							<h:message for="SWIFT" class="errorMsg" />
						</h:outputLabel></td>
				</tr>
				<tr>
					<td><h:outputLabel value="ДДС номер">
							<br />
							<h:inputText id="vat"
								value="#{aktualiziraneNaZastrahovatel.VATNumber}" maxlength="11"
								required="false"
								readonly="#{!aktualiziraneNaZastrahovatel.rowSelected}"
								validatorMessage="ДДС номерът се състои от 11 символа - главни латински букви и цифри.">
								<f:validateRegex pattern="^[A-Z0-9]{11}$" />
							</h:inputText>
							<br/>
							<h:message for="vat" class="errorMsg" />
						</h:outputLabel></td>
					<td colspan="2"><h:outputLabel
							value="Единен идентификационен код (ЕИК)*">
							<br />
							<h:inputText id="regnumber"
								value="#{aktualiziraneNaZastrahovatel.registrationNumber}"
								maxlength="9" required="true"
								requiredMessage="задължително поле!"
								readonly="#{!aktualiziraneNaZastrahovatel.rowSelected}"
								validatorMessage="ЕИК трябва да се състои от точно 9 цифри.">
								<f:validateRegex pattern="^[0-9]{9}$" />
							</h:inputText>
							<br/>
							<h:message for="regnumber" class="errorMsg" />
						</h:outputLabel> <h:commandButton value="Запази" class="regButton"
							style="width:80px;height:40px;margin-left:20px;"
							action="#{aktualiziraneNaZastrahovatel.writeIt()}"
							disabled="#{!aktualiziraneNaZastrahovatel.rowSelected or !aktualiziraneNaZastrahovatel.changingAllowed}" />
					</td>




				</tr>
			</table>
		</h:form>

		<h:form>
			<!-- формата е разделена на две, за да не се проверяват данните
			при натискането на бутоните "Отмени" и "Добави" -->
			<table class="buttonTable">
				<tr>
					<td><h:commandButton
							action="#{aktualiziraneNaZastrahovatel.deselectRow()}"
							value="Отмени" class="regButton" style="width:80px;height:40px;"
							disabled="#{!aktualiziraneNaZastrahovatel.rowSelected}" /> <h:commandButton
							action="#{aktualiziraneNaZastrahovatel.goToAdd()}" value="Добави"
							class="regButton" style="width:80px;height:40px;"
							disabled="#{!aktualiziraneNaZastrahovatel.goToAddAllowed}" /></td>
				</tr>
				<tr>
					<td><h:outputText
							value="#{dobavqneNaZastrahovatel.errorMessage}" /></td>
				</tr>
			</table>
		</h:form>

	</ui:define>

</ui:composition>
</html>